package com.otaku.admin.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.otaku.admin.dao.entity.Token;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.security.core.parameters.P;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface TokenMapper extends BaseMapper<Token> {

    List<Token> findByUserId(@Param("userId") String userId,@Param("status")Integer status);

    void updateStatusByUserId(@Param("userId") Integer userId, @Param("status") Integer status, @Param("originalStatus") Integer originalStatus);

    List<Token> findByTokenAndUserId(@Param("token") String token, @Param("userId") String userId, @Param("status") Integer status);

    Token findByRefreshToken(@Param("refreshToken") String refreshToken, @Param("status") Integer status);

    @Select("SELECT\n" +
            "        *\n" +
            "        FROM\n" +
            "        sys_token where status = #{status}  and access_token = #{accessToken}")
    Token findByAccessToken(@Param("accessToken") String accessToken, @Param("status") Integer status);
}
